
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Abahe
 */
public class Board extends GameCanvas implements Runnable {

    MMIDlet midlet;
    //=======================================//
    //test speed
    private int iTestSpeed;
    //=======================================//
    //xy
    private int xBoard;
    private int yBoard;
    //=======================================//
    //size
    private int boardWidth;
    private int boardHeight;
    //=======================================//
    //boolean
    private boolean running = false;
    //=======================================//
    //thread
    private long time = 0;
    private int speedGame = 200;

    public Board(MMIDlet midlet) {
        super(false);
        setFullScreenMode(true);        
        this.midlet = midlet;

        xBoard = 10;
        yBoard = 10;
        
    }

    protected void keyPressed(int keyCode) {
        super.keyPressed(keyCode);

        if (keyCode == -7) {
            System.out.println("yuk ah");
            midlet.exit();
        }
    }

    public void start() {
        running = true;
        Thread t = new Thread(this);
        t.start();
    }

    public void run() {
        Graphics g = getGraphics();
        //with        
        while (running) {
            time = System.currentTimeMillis();            
            iTestSpeed++;
            drawDisplay(g);
            time = speedGame - (System.currentTimeMillis() - time);
            try {
                Thread.sleep((time < 0 ? 0 : time));
            } catch (InterruptedException ie) {
            }
        }
        //without
        /*
        while (running) {
            //time = System.currentTimeMillis();
            iTestSpeed++;
            drawDisplay(g);
            //time = speedGame - (System.currentTimeMillis() - time);
            try {
                Thread.sleep(speedGame);
                //Thread.sleep((time < 0 ? 0 : time));
            } catch (InterruptedException ie) {
            }
        }
         * 
         */
    }

    private void drawDisplay(Graphics g){
        g.setColor(0xffffff);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(0x0000ff);
        g.drawString("caw ah", 20, 20, Graphics.TOP | Graphics.LEFT);

        g.drawString(String.valueOf(iTestSpeed), 50, 50, Graphics.TOP | Graphics.LEFT);
        
        flushGraphics();
    }
}
